From 66d0ad3edcaa5308b4d0397b8f8775d7fa0bc1a6 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sun, 4 Feb 2024 07:45:47 -0800
Subject: feat(badges): aggressive service-side caching

---
 src/routes/user/[user]/badges/+page.svelte | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

(limited to 'src/routes/user/[user]/badges/+page.svelte')

diff --git a/src/routes/user/[user]/badges/+page.svelte b/src/routes/user/[user]/badges/+page.svelte
index 24a3de8f..f40837ed 100644
--- a/src/routes/user/[user]/badges/+page.svelte
+++ b/src/routes/user/[user]/badges/+page.svelte
@@ -283,8 +283,22 @@
 			}, {});
 	};
 
-	const thumbnail = (url: string | undefined) =>
-		url && url.includes('catbox.moe') ? url.replace('catbox.moe/', 'catbox.moe/thumbs/t_') : url;
+	const thumbnail = (url: string | undefined) => {
+		if (url && url.includes('catbox.moe') && !url.includes('gif'))
+			return url.replace('catbox.moe/', 'catbox.moe/thumbs/t_');
+
+		if (url && url.includes('discordapp')) {
+			const match = url.match(/attachments\/(\d+)\/(\d+)\/(.+)/);
+
+			if (match) {
+				const [_, server, id, file] = match;
+
+				return `https://media.discordapp.net/attachments/${server}/${id}/${file}?width=144&height=200`;
+			}
+		}
+
+		return url;
+	};
 </script>
 
 <HeadTitle route={`${data.username}'s Badge Wall`} path={`/user/${data.username}`} />
-- 
cgit v1.2.3

